package demoMod.invincibleOne.events;

import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.curses.Doubt;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.events.AbstractImageEvent;
import com.megacrit.cardcrawl.helpers.CardLibrary;
import com.megacrit.cardcrawl.localization.EventStrings;
import com.megacrit.cardcrawl.vfx.cardManip.PurgeCardEffect;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardAndObtainEffect;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.cards.invincible.InvincibleForm;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Chat extends AbstractImageEvent {
    public static final String ID = InvincibleOneMod.makeID("Chat");

    private static final EventStrings eventStrings = CardCrawlGame.languagePack.getEventString(ID);

    public static final String NAME = eventStrings.NAME;
    public static final String[] DESCRIPTIONS = eventStrings.DESCRIPTIONS;
    public static final String[] OPTIONS = eventStrings.OPTIONS;

    private int screenNum = 0;

    public Chat() {
        super(NAME, DESCRIPTIONS[0], InvincibleOneMod.getResourcePath("events/chat.png"));
        this.imageEventText.setDialogOption(OPTIONS[0], new Doubt());
        AbstractCard preview = new InvincibleForm();
        preview.upgrade();
        this.imageEventText.setDialogOption(OPTIONS[1], preview);
        this.imageEventText.setDialogOption(OPTIONS[2]);
    }

    protected void buttonEffect(int buttonPressed) {
        switch (this.screenNum) {
            case 0:
                switch (buttonPressed) {
                    case 0:
                        AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(new Doubt(), Settings.WIDTH / 2.0F, Settings.HEIGHT / 2.0F));
                        this.imageEventText.updateBodyText(DESCRIPTIONS[1]);
                        this.screenNum = 1;
                        this.imageEventText.updateDialogOption(0, OPTIONS[3]);
                        this.imageEventText.clearRemainingOptions();

                        InvincibleOneMod.provoked[CardCrawlGame.saveSlot] = false;
                        InvincibleOneMod.save.setBool("provoked" + CardCrawlGame.saveSlot, false);
                        try {
                            InvincibleOneMod.save.save();
                        } catch (IOException e) {}

                        return;
                    case 1:
                        AbstractCard preview = new InvincibleForm();
                        preview.upgrade();
                        AbstractDungeon.effectList.add(new ShowCardAndObtainEffect(preview, Settings.WIDTH / 2.0F, Settings.HEIGHT / 2.0F));
                        this.imageEventText.updateBodyText(DESCRIPTIONS[2]);
                        this.screenNum = 1;
                        this.imageEventText.updateDialogOption(0, OPTIONS[3]);
                        this.imageEventText.clearRemainingOptions();

                        InvincibleOneMod.provoked[CardCrawlGame.saveSlot] = false;
                        InvincibleOneMod.save.setBool("provoked" + CardCrawlGame.saveSlot, false);
                        try {
                            InvincibleOneMod.save.save();
                        } catch (IOException e) {}

                        return;
                    default:
                        List<AbstractCard> rm = new ArrayList<>();
                        for (AbstractCard c: AbstractDungeon.player.masterDeck.group) {
                            if (c.rarity != AbstractCard.CardRarity.BASIC) {
                                rm.add(c);
                            }
                        }
                        for (AbstractCard c: rm) {
                            AbstractDungeon.topLevelEffects.add(new PurgeCardEffect(c, (float) Settings.WIDTH / 2.0F, (float)Settings.HEIGHT / 2.0F));
                            AbstractDungeon.player.masterDeck.removeCard(c);
                        }

                        InvincibleOneMod.save.setBool("provoked" + CardCrawlGame.saveSlot, true);
                        InvincibleOneMod.provoked[CardCrawlGame.saveSlot] = true;
                        try {
                            InvincibleOneMod.save.save();
                        } catch (IOException e) {}

                        this.imageEventText.updateBodyText(DESCRIPTIONS[3]);
                        this.screenNum = 1;
                        this.imageEventText.updateDialogOption(0, OPTIONS[3]);
                        this.imageEventText.clearRemainingOptions();
                        return;
                }
            case 1:
                openMap();
                return;
        }
        openMap();
    }
}
